package com.bupt.vueblog.constant;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * @author 谭继好
 * @Description 后端封装的返回给前端的结果类，前端获取并展示
 * @date 2024-04-09 20:32
 */
@Data
@AllArgsConstructor
public class Result<T> implements Serializable {

    private int code;
    private String message;
    private Object data;

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Result success() {
        return new Result(Status.SUCCESS, Message.SUCCESS);
    }

    public static Result success(Object data) {
        return new Result(Status.SUCCESS, Message.SUCCESS, data);
    }

    public static Result fail(int code, String message) {
        return new Result(code, message);
    }
}
